﻿// 功能：Shell通知消息演示窗口
// 描述：
// 作者：温伟鹏
// 日期：2010/10/12 14:35:37

using System;
using MeizuSDK.Presentation;
using MeizuSDK.Core;
using System.IO;

namespace Demo
{
    class ShellNotificationWindow : DemoWindowBase
    {
        Button m_SoundBtn;
        Button m_VibrateBtn;
        Button m_Sound_VibrateBtn;
        Button m_Dialog;
        Button m_Image;

        IntPtr notifyHandle;

        public ShellNotificationWindow()
            : base()
        {

        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            m_SoundBtn = new Button();
            m_SoundBtn.Text = "响铃";
            m_SoundBtn.Location = new System.Drawing.Point(100, 100);
            m_SoundBtn.Click += new EventHandler(m_SoundBtn_Click);

            m_VibrateBtn = new Button();
            m_VibrateBtn.Text = "震动";
            m_VibrateBtn.Location = new System.Drawing.Point(100, 200);
            m_VibrateBtn.Click += new EventHandler(m_VibrateBtn_Click);

            m_Sound_VibrateBtn = new Button();
            m_Sound_VibrateBtn.Text = "响铃\t震动";
            m_Sound_VibrateBtn.Location = new System.Drawing.Point(100, 300);
            m_Sound_VibrateBtn.Click += new EventHandler(m_Sound_VibrateBtn_Click);

            m_Dialog = new Button();
            m_Dialog.Text = "对话框";
            m_Dialog.Location = new System.Drawing.Point(100, 400);
            m_Dialog.Click += new EventHandler(m_Dialog_Click);

            m_Image = new Button();
            m_Image.Text = "图像";
            m_Image.Location = new System.Drawing.Point(100, 500);
            m_Image.Click += new EventHandler(m_Image_Click);

            Controls.Add(m_SoundBtn);
            Controls.Add(m_VibrateBtn);
            Controls.Add(m_Sound_VibrateBtn);
            Controls.Add(m_Dialog);
            Controls.Add(m_Image);
        }

        void m_Image_Click(object sender, EventArgs e)
        {
            MzUserNotification notification = new MzUserNotification();
            notification.ActionFlags = ShellNotifyMsg.MUN_IMAGE_S;
            notification.szImageSmall = Path.Combine(Application.StartupPath, "Images\\Clock.png");
            notification.bIsIconBlink = 1;

            notifyHandle = ShellNotifyMsg.MzSetUserNotification(notifyHandle, ref notification);
        }

        void m_Dialog_Click(object sender, EventArgs e)
        {
            MzUserNotification notification = new MzUserNotification();
            notification.ActionFlags = ShellNotifyMsg.MUN_DIALOG;
            notification.szTiTle = "对话框通知消息";
            notification.szTip = "俺是对话框通知消息！";
            notification.szDefaultBtnName = "卡卡";
            notification.szCustomBtnName = "QQ";
            notification.DefaultIconType = ShellNotifyMsg.MUN_ICON_TYPE_OPEN;
            notification.CustomIcontype = ShellNotifyMsg.MUN_ICON_TYPE_HIDE;

            notifyHandle = ShellNotifyMsg.MzSetUserNotification(notifyHandle, ref notification);
        }

        void m_Sound_VibrateBtn_Click(object sender, EventArgs e)
        {
            MzUserNotification notification = new MzUserNotification();
            notification.ActionFlags = ShellNotifyMsg.MUN_SOUND | ShellNotifyMsg.MUN_VIBRATE;
            notification.dwPlaySoundPeriod = 0;
            notification.dwVibratePeriod = 0;//随音乐震动
            notification.szSound = @"\\Windows\\RingTone\\信息_精灵.lnk";

            notifyHandle = ShellNotifyMsg.MzSetUserNotification(notifyHandle, ref notification);
        }

        void m_VibrateBtn_Click(object sender, EventArgs e)
        {
            MzUserNotification notification = new MzUserNotification();
            notification.ActionFlags = ShellNotifyMsg.MUN_VIBRATE;
            notification.dwVibratePeriod = 3;

            notifyHandle = ShellNotifyMsg.MzSetUserNotification(notifyHandle, ref notification);
        }

        void m_SoundBtn_Click(object sender, EventArgs e)
        {
            MzUserNotification notification = new MzUserNotification();
            notification.ActionFlags = ShellNotifyMsg.MUN_SOUND;
            notification.dwPlaySoundPeriod = 0;
            notification.szSound = @"\\Windows\\RingTone\\信息_精灵.lnk";

            notifyHandle = ShellNotifyMsg.MzSetUserNotification(notifyHandle, ref notification);
        }

        protected override void Dispose(bool disposing)
        {
            if (notifyHandle != IntPtr.Zero)
            {
                ShellNotifyMsg.MzClearUserNotification(notifyHandle);
            }

            base.Dispose(disposing);
        }
    }
}
